<template>
  <div class="third">
    <div class="common">
      <div class="common-input">
        <el-input style="width: 300px" v-model="commonValue" placeholder="商品名称/店铺名称/昵称/手机号" clearable></el-input>
      </div>

      <div class="common-input">
        <el-select v-model="commonStateValue" placeholder="请选择状态" clearable>
          <el-option v-for="item in commonStateOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>

      <div class="common-input">
        <el-select v-model="commonShopValue" placeholder="请选择时间类型" clearable>
          <el-option v-for="item in commonShopOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div>

      <div class="common-input">
        <el-date-picker v-model="commonDate" type="daterange" range-separator="至" start-placeholder="开始日期"
          end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
        </el-date-picker>
      </div>

      <div class="common-button" @click="searchHit">搜索</div>
      <div class="common-button" @click="replacementHit">重置</div>
    </div>


    <div class="table" v-loading="loading">
      <el-table :data="tableData" border :header-cell-style="{
        color: '#333333',
        backgroundColor: '#f3f3f3',
      }">
        <el-table-column label="用户信息" width="300">
          <template slot-scope="scope">
            <div class="consumers">
              <div class="right">
                <div class="title">{{ scope.row.nickname }}</div>
                <div class="name">{{ scope.row.phone }}</div>
              </div>
            </div>
          </template>
        </el-table-column>

        <el-table-column label="商品信息">
          <template slot-scope="scope">
            <div class="merchandise">
              <div class="left">
                <img :src="scope.row.goodStockImage" alt="">
              </div>
              <div class="right">
                <div class="title">{{ scope.row.goodName }}</div>
                <div class="name">
                  {{ scope.row.goodStockProperty }} <span style="margin-left: 10px;">￥{{ scope.row.retailPrice }}
                  </span>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="订单号" width="200">
          <template slot-scope="scope">
            {{ scope.row.orderNo }}
          </template>
        </el-table-column>

        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.orderStatus == 'WAIT'">待付款</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'PAYMENT'">已付款</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'CANCEL'">已取消</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'SEND'">待发货</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'START'">已发货</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'SIGN'">待签收</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'FINISH'">已签收</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'REJECTION'">已拒收</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'AFTER'">售后中</el-tag>
            <el-tag v-else-if="scope.row.orderStatus == 'RETURN'">售后完成</el-tag>
          </template>
        </el-table-column>

        <el-table-column prop="createTime" label="下单时间" width="200">
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
          layout="prev, pager, next" :total="tableDataTotal" :current-page="page">
        </el-pagination>
      </div>
    </div>

    <!--处理弹出框-->
    <div class="official">
      <el-dialog title="删除" :visible.sync="deteleVisible" :before-close="deteleClose" round>
        <div class="official-title">是否确认删除？</div>
        <div class="official-attachment">
          <div class="list" @click="deteleClose">取消</div>
          <div class="list">确定</div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  orderList
} from '@/api/order'

export default {
  data() {
    return {
      commonValue: "",
      commonStateValue: "",
      commonStateOptions: [
        {
          value: "-1",
          label: "全部",
        },
        {
          value: "WAIT",
          label: "待付款",
        },
        {
          value: "PAYMENT",
          label: "已付款",
        },
        {
          value: "SEND",
          label: "待发货",
        },
        {
          value: "START",
          label: "已发货",
        },
        {
          value: "SIGN",
          label: "待签收",
        },
        {
          value: "FINISH",
          label: "已签收",
        },
      ],
      commonShopValue: "",
      commonShopOptions: [
        {
          value: "0",
          label: "创建时间",
        },
        {
          value: "1",
          label: "支付时间",
        },
        {
          value: "2",
          label: "发货时间",
        },
        {
          value: "3",
          label: "签收时间",
        },
      ],
      commonDate: [],
      commonStart: "",
      commonEnd: "",
      //-------------
      page: 1,
      limit: 10,
      tableData: [],
      tableDataTotal: 0,
      loading: false,
      commonObj: {},
      //------------
      deteleVisible: false,
    };
  },
  created() {
    this.orderListMet()
  },
  methods: {
    orderListMet() {
      let params = {
        orderType: 3,
        orderStatus: this.commonStateValue == -1 ? '' : this.commonStateValue,
        keyWord: this.commonValue,
        timeType: this.commonShopValue,
        startTime: this.commonStart,
        endTime: this.commonEnd,

        pageSize: this.limit,
        pageNo: this.page,
      }

      orderList(params).then(res => {
        if (res.errorCode == null) {
          res.resultData.orderList.forEach((item, index) => {
            item.paymentPrice = Number(item.paymentPrice / 100).toFixed(2);
            item.retailPrice = Number(item.retailPrice / 100).toFixed(2);
            item.price = Number(item.price / 100).toFixed(2);
            item.realityFreight = Number(item.realityFreight / 100).toFixed(2);

          });

          this.tableData = res.resultData.orderList;
          this.tableDataTotal = res.resultData.totalNum;
          this.loading = false;
        }
      })
    },
    //-------------
    timeData(date) {
      return date.toLocaleString("zh-CN", {
        year: "numeric",
        month: "2-digit",
        day: "2-digit",
        // hour: "2-digit",
        // minute: "2-digit",
        // second: "2-digit",
      });
    },
    searchHit() {
      if (this.commonDate.length > 0) {
        this.commonStart = this.timeData(new Date(this.commonDate[0]));
        this.commonEnd = this.timeData(new Date(this.commonDate[1]));
      } else {
        this.commonStart = "";
        this.commonEnd = "";
      }

      this.page = 1;
      this.loading = true;
      this.orderListMet();
    },
    replacementHit() {
      this.commonDate = [];
      this.commonStart = "";
      this.commonEnd = "";
      this.commonValue = "";
      this.commonStateValue = "";
      this.commonShopValue = ''

      this.page = 1;
      this.loading = true;
      this.orderListMet();
    },

    //---------------
    detailsHit() {
      this.$router.push({
        path: "/order/third/third-list-details",
      });
    },
    deteleHit() {
      this.deteleVisible = true;
    },
    deteleClose() {
      this.deteleVisible = false;
    },
    //---------
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      this.orderListMet();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      this.orderListMet();
    },
  },
};
</script>

<style lang="less" scoped>
@import url("@/assets/css/official.less");

.third {
  .common {
    margin-bottom: 10px;
    display: flex;
    align-items: center;

    .common-input {
      margin-right: 10px;

      /deep/ .el-input {
        width: 250px;
      }
    }

    .common-input:last-child {
      margin-right: 0;
    }

    .common-button {
      padding: 9px 20px;
      box-sizing: border-box;
      border-radius: 5px;
      background: #2a82e4;
      font-size: 14px;
      color: #fff;
      margin-left: 20px;
      cursor: pointer;
    }

    .common-button:last-child {
      background: #999999;
    }

    .common-button:first-child {
      margin-left: 0;
    }
  }

  .table {
    cursor: pointer;

    .consumers {
      display: flex;

      .left {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        border: 1px solid;
        margin-right: 10px;
      }

      .right {}
    }

    .merchandise {
      display: flex;

      .left {
        width: 70px;
        height: 70px;
        border-radius: 2px;
        border: 1px solid;
        margin-right: 10px;
      }

      .right {
        .fanli {
          font-weight: bold;
          color: red;
        }
      }
    }

    .operation {
      display: flex;
      align-items: center;
      color: #2a82e4;

      .list {
        margin-right: 20px;
        cursor: pointer;
      }
    }

    .imgs {
      width: 50px;
      height: 50px;
    }
  }
}
</style>